package com.zjl.cms.dao;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.zjl.cms.model.User;

@Repository
public class BaseDao {
	
	@Autowired
	private SqlSessionFactory sqlSessionFactory;
	
	public List selectAll(String sql){
		List res=null;
		try {
			SqlSession session = sqlSessionFactory.openSession();
			res = session.selectList(sql);
			session.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return res;
	}

	public List select(String sql, Object object) {
		List res=null;
		try {
			SqlSession session = sqlSessionFactory.openSession();
			res = session.selectList(sql,object);
			session.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return res;
	}
	
	public Object selectOne(String sql, Object object) {
		Object res=null;
		try {
			SqlSession session = sqlSessionFactory.openSession();
			res = session.selectOne(sql,object);
			session.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return res;
	}
}
